package com.csust.travel.controller;


import com.csust.travel.entity.*;
import com.csust.travel.mapper.TransactionCommentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RequestMapping("/transaction_comment")
@RestController
public class TransactionCommentController {
    @Autowired
    TransactionCommentMapper transactionCommentMapper;
    @RequestMapping("/page")
    public ResBean page(@RequestBody pageDate pagination){
        PageHelper.startPage(pagination.getCurrentPage(),pagination.getPageSize());
        List<TransactionComment> Items;
        if (pagination.getQueryString() == null || pagination.getQueryString().trim().equals("")){
            Items = transactionCommentMapper.findAllItem();
        }else {
            Items = transactionCommentMapper.findByString(pagination.getQueryString());
        }

        PageInfo<TransactionComment> commentPageInfo = new PageInfo<>(Items);

        return new ResBean(true,null,commentPageInfo);
    }

    @RequestMapping("/one")
    public ResBean findOne(Integer id){
        NewTransactionComment newTransactionComment = new NewTransactionComment();
        newTransactionComment.setTransaction_id(transactionCommentMapper.findThree(id));
        newTransactionComment.setBuyer_id(transactionCommentMapper.findOne(id));
        newTransactionComment.setSeller_id(transactionCommentMapper.findTwo(id));
        newTransactionComment.setComment(transactionCommentMapper.findFive(id));
        newTransactionComment.setComment_date(transactionCommentMapper.findSix(id));
        newTransactionComment.setRating(transactionCommentMapper.findFour(id));
        newTransactionComment.setBook_id(transactionCommentMapper.findSeven(id));
        newTransactionComment.setBook_name(transactionCommentMapper.findEight(transactionCommentMapper.findSeven(id)));
        return new ResBean(true,null,newTransactionComment);

    }
    @RequestMapping("/del")
    public  ResBean delItem(Integer id){
        try {
            transactionCommentMapper.delItem(id);
            return new ResBean(true,"删除成功666");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResBean(false,"删除失败");
    }


}
